<?php
session_start();
    require_once "config.php";
    $username=trim($_POST['username']);
    $password=trim($_POST['password']);
    $sql="select * from admin where name='{$username}'";

    $rst=mysqli_query($con,$sql);
    $row=mysqli_fetch_assoc($rst);
    if($username==$row['name']&&$password==$row['password']){
        $_SESSION['username'] = $username;
        $_SESSION['time'] = time();
        $times = $row['times']+1;
        $sql1 = "update admin set times = $times";
        $rst = mysqli_query($con,$sql1);
        echo "<script>alert('登录成功');window.location.href='index.php';</script>";

    }else{
        echo "<script>alert('用户名或密码错误,请重新登录');window.location.href='login.php';</script>";
    }